#include<bits/stdc++.h>
#define ll long long
#define L x<<1
#define R x<<1|1
#define mid ((l+r)>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define Root 1,1,n
#define OK Ll<=l&&r<=Rr
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned ll
#define yy puts("Yes"),exit(0)
#define nn puts("No"),exit(0)
#define YY return puts("Yes"),void()
#define NN return puts("No"),void()
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N=1e5+5,M=1e6+5,inf=(1LL<<30)-1,mod=1e9+7;
const ll llf=1e18;
inline void add(int &a,int b){if(b<0)b+=mod;((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){add(b,mod);return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,ll b){if(!b)return 1;int c=qp(a,b>>1LL);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
inline bool che(int x,int p){return (x>>p)&1LL;}
bool St;
int n,m,k,t;
struct node{
	int x,y;
}a[N],b[N],A[N];
inline bool cmp(node a,node b){
	return a.x==b.x?a.y>b.y:a.x>b.x;
}

int g[N];
vector<int>pl[N],pr[N];
ll dp[1005][1005][2];//0:左线头 1:右线头 (i后面那一段)
inline ll calc(int i,int t){
	return max(a[t].y-b[i].y,0)+max(a[t].x-b[i].x,0);
}
inline void subtask1(){
	repm(i){
		int l=1,r=n,le=n+1,re=0;
		while(l<=r)if(a[mid].y<=b[i].y)le=mid,r=mid-1;
		else l=mid+1;
		l=1,r=n;
		while(l<=r)if(a[mid].x<=b[i].x)re=mid,l=mid+1;
		else r=mid-1;
		if(le<=re){
			g[le]++,g[re+1]--;
			pl[le].pb(b[i].y),pr[re].pb(b[i].x);
		}
		A[i]={le,re};
	}
	repn(i)g[i]+=g[i-1];
	rep(i,0,n+1)rep(j,0,m+1)rep(f,0,1)dp[i][j][f]=llf;
	//规定特殊点只生成右线头
	repm(i)if(A[i].x>A[i].y)dp[1][i][1]=calc(i,1);//特殊点生成右线头
	if(g[1]){
		dp[1][0][0]=0;
		repm(i)if(A[i].x<=A[i].y){
			if(A[i].y==1)dp[1][i][1]=a[2].x-b[i].x;//普通点生成右线头
			//普通点预定左线头,此处不需要
		}
	}else {
		//必须生成线头
		repm(i)if(A[i].x<=A[i].y){
			//普通点生成右线头,此处不存在
			if(A[i].x==2)dp[1][0][0]=min(dp[1][0][0],(ll)a[1].y-b[i].y);//直接结算左线头
			else dp[1][i][0]=a[1].y-a[2].y;//预定左线头
		}
	}
	rep(i,2,n){
		ll Mn=llf,Mnh=llf;
		rep(j,0,m)rep(f,0,1)if(!(A[j].x<=A[j].y&&f==0))Mn=min(Mn,dp[i-1][j][f]);
		// repm(j)if(A[j].x<=A[j].y)Mnh=min(Mnh,min(dp[i-1][j][1],dp[i-1][j][0]));//有过右线头或尚未结算的左线头
		repm(j)if(A[j].x>A[j].y){
			//特殊点生成右线头
			dp[i][j][1]=Mn+calc(j,i);
			if(i<=A[j].y)dp[i][j][1]=min(dp[i][j][1],dp[i-1][j][1]);//直接继承
			else dp[i][j][1]=min(dp[i][j][1],dp[i-1][j][1]+a[i].x-max(b[j].x,a[i-1].x));//加上额外的一段
		}
		//普通点
		if(g[i]){
			dp[i][0][0]=Mn;//什么都不做
			repm(j)if(A[j].x<=A[j].y){
				//左线头
				if(A[j].x==i+1)dp[i][0][0]=min(dp[i][0][0],dp[i-1][j][0]+(ll)a[i].y-b[j].y);//直接结算左线头
				else if(A[j].x>i+1)dp[i][j][0]=min(Mn,dp[i-1][j][0])+a[i].y-a[i+1].y;//预定
				//右线头
				if(A[j].y==i){//生成右线头
					dp[i][j][1]=Mn+a[i+1].x-b[j].x;
				}else if(A[j].y<i){
					dp[i][j][1]=dp[i-1][j][1]+a[i+1].x-a[i].x;//继承右线头
				}
			}
		}else {
			dp[i][0][0]=llf;
			repm(j)if(A[j].x<=A[j].y){
				if(A[j].y<i){//右线头
					dp[i][j][1]=dp[i-1][j][1]+a[i+1].x-a[i].y;//继承右线头
					dp[i][0][0]=min(dp[i][0][0],dp[i-1][j][1]);
				}
				if(A[j].x==i+1)dp[i][0][0]=min(dp[i][0][0],dp[i-1][j][0]+(ll)a[i].y-b[j].y);//直接结算左线头
				else if(A[j].x>i+1)dp[i][j][0]=min(Mn,dp[i-1][j][0])+a[i].y-a[i+1].y;//预定
			}
		}
	}
	ll Mn=llf;
	rep(j,0,m)rep(f,0,1)if(!(A[j].x<=A[j].y&&f==0))Mn=min(Mn,dp[n][j][f]);//只要没有残留的就行
	cout <<Mn;
}
inline void Main(){
	n=read(),m=read(),k=read();
	repn(i)a[i].x=read(),a[i].y=read();
	repm(i)b[i].x=read(),b[i].y=read();
	sort(a+1,a+n+1,cmp);
	int Mx=-1;
	repn(i)if(Mx<a[i].y)A[++t]=a[i],Mx=a[i].y;
	rep(i,1,t)a[i]=A[t-i+1];
	n=t;
	return subtask1();
	
}
bool Ed;
signed main(){
	freopen("move.in","r",stdin);
	freopen("move.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}
